package com.example.userdemo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.example.userdemo.entity.Student;
import com.example.userdemo.mapper.StudentMapper;
import com.example.userdemo.service.StudentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liqinglin
 * @since 2023年07月24日
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void queryAndSave(int age) {
        Student student = this.baseMapper.selectOne(new LambdaQueryWrapper<Student>()
                .eq(Student::getAge, age));
//        try {
//            Thread.sleep(120000);
//        } catch (InterruptedException e) {
//            throw new RuntimeException(e);
//        }
        List<Student> students = this.baseMapper.selectList(new LambdaQueryWrapper<Student>()
                .eq(Student::getSex, age));
        System.out.println("--当前线程结束" + Thread.currentThread().getName());
    }
}
